package servlet.Person;

import domain.Info;
import service.person.PersonService;
import service.person.PersonServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class Person extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub

        if(request.getSession().getAttribute("userloginflag")==null){
            request.getRequestDispatcher("/index.jsp").forward(request, response);
        }
        else {
            if (request.getParameter("info_id")==null ||request.getParameter("info_id")==""){
                request.getRequestDispatcher("/admin/error/error404.jsp").forward(request, response);
                return;
            }else {
                PersonService personService = new PersonServiceImpl();
                int info_id = Integer.parseInt(request.getParameter("info_id"));
                Info info = personService.getInfoById(info_id);
                request.setAttribute("person", info);
                request.getRequestDispatcher("/app/person/info.jsp").forward(request, response);
                return;
            }
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}